package org.jsbd.boss.action;

import javax.servlet.http.HttpServletResponse;

import org.jsbd.boss.common.ResponseUtils;
import org.jsbd.boss.domian.channel.BaseResultVo;
import org.jsbd.boss.domian.channel.MomoUser;
import org.jsbd.boss.enums.ResponseEnum;
import org.jsbd.boss.service.IMomoUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;


@Controller
@RequestMapping("/momo")
public class MomoUserController {
	public static final Logger LOGGER = LoggerFactory.getLogger(MomoUserController.class);

	@Autowired
	private IMomoUserService momoUserService;
	
	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public void save(HttpServletResponse response, MomoUser user) {
		BaseResultVo resultVo = new BaseResultVo();
		try {
			if (!momoUserService.saveMomoUser(user)) {
				resultVo.setStatus(ResponseEnum.FAIL.getStatus());
				resultVo.setMessage("请求参数非法或者已经注册过!");
			}
		} catch (Exception e) {
			LOGGER.error("保存陌陌用户信息失败{}",user, e);
			resultVo.setStatus(ResponseEnum.ERROR.getStatus());
			resultVo.setMessage(e.getMessage());
		}
		ResponseUtils.renderJson(response, resultVo.toString());
	}

}
